package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

//    //获取当前页的结果列表
//    public List<Employee> getByName(String name,int page,int pageSize) ;

//    @Select("select * from employee where name like '%#{name}%' limit #{start},#{pageSize}")
//    List<Employee> getByName(String name,int start, int pageSize);

//    @Select("select count(*) from employee where name like concat('%',#{name},'%')")
//    int getTotalByName(String name);

    @Insert("INSERT into employee (name,username,password,phone,sex,id_number,status,create_time,update_time,create_user,update_user) " +
            "values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void addEmployee(Employee employee);

//    @Select("select count(*) from employee")
//    int getTotal();

    Page<Employee> getPage(String name , int start, int pageSize);

    @Update("update employee set status = #{status} where id = #{id}")
    @AutoFill(value = OperationType.UPDATE)
    void updateStatus(Integer status,int id);

    @AutoFill(value = OperationType.UPDATE)
    void updateEmployee(Employee employee);

    @Select("select id ,name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user from employee where id = #{id}")
    Employee getById(long id);
}
